import { Module } from '@nestjs/common';
// import { SessionModule } from '@nestjs/platform-express';
import { SessionModule } from 'nestjs-session';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from '@/entity/users/user.entity';
import { Publish } from '@/entity/form/form.entiy';
import { Report } from '@/entity/report/report.entiy';
import { Dic } from '@/entity/dic/dic.entity';
import { Collect } from '@/entity/collect/collect.entity';
import { Rocket } from '@/entity/rocket/rocket.entity';
import { UsersModule } from '@/modules/users/users.module';
import { FormModule } from '@/modules/form/form.module';
import { NameGenerationModule } from '@/modules/nameGeneration/nameGeneration.module';
import { AuthModule } from '@/modules/auth/auth.module';
import { ReportModule } from '@/modules/report/report.module';
import { DicModule } from '@/modules/dic/dic.module';
import { CollectModule } from '@/modules/collect/collect.module';
import { RocketModule } from '@/modules/rocket/rocket.module'
import { sessionSecret } from './constant'

@Module({
  imports: [
    ConfigModule.forRoot(), // 加载 .env 文件中的环境变量
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DB_HOST'),
        port: +configService.get('DB_PORT'),
        username: configService.get('DB_USERNAME'),
        password: configService.get('DB_PASSWORD'),
        database: configService.get('DB_DATABASE'),
        entities: [User, Publish, Report, Dic, Collect, Rocket],
        synchronize: false,
      }),
      inject: [ConfigService],
    }),
    // 导入 SessionModule 并配置选项
    SessionModule.forRoot({
      session: { secret: process.env.SESSION_SECRET },
    }),
    UsersModule,
    FormModule,
    NameGenerationModule,
    AuthModule,
    ReportModule,
    DicModule,
    CollectModule,
    RocketModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
